package com.atguigu.dao.impl;

import com.atguigu.dao.AccountDao;
import com.atguigu.pojo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class AccountDaoImpl implements AccountDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 更新账户的余额
     */
    @Override
    public int updateAccount(Account account) {
        String sql = "update account set money = ? where name = ?";
        return jdbcTemplate.update(sql,account.getMoney(),account.getName());
    }
    /**
     * 根据账户名查询账户信息
     */
    @Override
    public Account queryAccountByName(String name) {
        String sql ="select * from account where name = ?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<Account>(Account.class),name);
    }
}
